import 'package:creatures_world/data/animal_data_tool.dart';
import 'package:creatures_world/pages/base/base_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get_navigation/src/root/get_material_app.dart';

import 'db/db_helper.dart';
import 'get/init_binding.dart';
import 'get/my_getobserver.dart';
import 'get/routers.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();


  DBHelper.openDb();
  AnimalDataTool.loadAnimalFiles();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MyHomePage(title: 'Flutter Demo Home Page');
  }
}

class MyHomePage extends StatefulWidget {

  const MyHomePage({super.key, required this.title});
  final String title;
  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {

    return ScreenUtilInit(
      designSize: const Size(375, 812),
      minTextAdapt: true,
      splitScreenMode: true,
      builder: (context, child) {
        return MediaQuery(
          data: MediaQuery.of(context).copyWith(textScaler: TextScaler.noScaling),
          child: GestureDetector(
            onTap: () {
              FocusScopeNode currentFocus = FocusScope.of(context);
              if (!currentFocus.hasPrimaryFocus) {
                debugPrint("这里需要关闭键盘-----");
                // currentFocus.unfocus();
                FocusScopeNode currentFocus = FocusScope.of(context);
                currentFocus.focusedChild?.unfocus();
              }
            },
            child: GetMaterialApp(
              debugShowCheckedModeBanner: false,
              // locale: const Locale('zh','CN'),
              locale: const Locale('en', 'US'),
              fallbackLocale: const Locale('en', 'US'),
              title: 'Creatures World',
              initialRoute: "/",
              navigatorObservers: [MyGetObserver()],
              initialBinding: InitBinding(),
              getPages: AppPage.routes,
            ),
          ),
        );
      },
    );

  }
}
